package com.jastar.android.game.cannon.model;

import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;

public class Projectile {
    private static final float TIME_SPEED_RATIO = 6F;
    private static final float SPEED = 2F;
    private final Paint paint;
    private float x, y;
    private float velocityX, velocityY;
    private float gravity = 98F;
    private float radius = 10F;
    private boolean isActive;

    public Projectile(float startX, float startY, float angle, float power) {
        this.x = startX;
        this.y = startY;
        float radians = (float) Math.toRadians(angle);
        this.velocityX = (float) (power * Math.cos(radians) * SPEED);
        this.velocityY = (float) -(power * Math.sin(radians) * SPEED);
        this.isActive = true;

        paint = new Paint();
        paint.setColor(Color.BLACK);
    }

    public void update(float deltaTime) {
        if (!isActive) return;

        velocityY += gravity * deltaTime;
        x += velocityX * deltaTime * TIME_SPEED_RATIO;
        y += velocityY * deltaTime * TIME_SPEED_RATIO;
    }

    public boolean isActive() {
        return isActive;
    }

    public float getX() {
        return x;
    }

    public float getY() {
        return y;
    }

    public void draw(Canvas canvas) {
        if (!isActive) return;
        canvas.drawCircle(x, y, radius, paint); // 使用常量半径
    }

    public void setActive(boolean active) {
        this.isActive = active;
    }

    public float getRadius() {
        return radius;
    }

}